#include "flip_internal.hpp"

#include <flip/2d/font.hpp>

using namespace Flip;

int flip_font_tag;


LUAF(load_font)
{
	char const* path = luaL_checkstring(L, 1);
	// TODO: Validate path

	int size = luaL_checkint(L, 2);

	LUA_NEW_OBJ(Font, self, flip_font_tag, (path, size));
	
	return 1;
}

LUAF(text)
{
	luaflipData& data = globalData(L);
	auto& font = check_font(L, 1);

	char const* str = luaL_checkstring(L, 2);
	double x = luaL_checknumber(L, 3);
	double y = luaL_checknumber(L, 4);

	font.drawText(data.drawBuffer, str, x, y);
	return 0;
}

LUAF(font_gc)
{
	auto& image = check_font(L, 1);

	luaext_setuserdatatag(L, 1, 0);
	image.~Font();
	
	return 0;
}